// pages/modify/modify.js
let app = getApp();
Page({
  data: {
    weekList: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],
    weekIndex: '',
    scheduleId: '',
    kctitle: '',
    place: '',
    content: '',
    week: '',
    xingqi: '',
    jieci: '',
    changdu: '',
    remindtime: '',
    flag: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this;
    console.log(options)
    that.setData({
      scheduleId: options.scheduleId,
      kctitle: options.kctitle,
      place: options.place,
      content: options.content,
      week: options.week,
      xingqi: options.xingqi,
      jieci: options.jieci,
      changdu: options.changdu,
      remindtime: options.remindtime,
      flag: options.flag,
      weekIndex: parseInt(options.week)-1
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  bindWeekChange: function (e) {
    let that = this;
    that.setData({
      week: that.data.weekList[e.detail.value],
      weekIndex: e.detail.value
    })
  },
  inputTitleChange: function (e) {
    this.setData({
      kctitle: e.detail.value
    })
  },
  inputPlaceChange: function (e) {
    this.setData({
      place: e.detail.value
    })
  },
  inputContentChange: function (e) {
    this.setData({
      content: e.detail.value
    })
  },
  inputXingqiChange: function (e) {
    this.setData({
      xingqi: e.detail.value
    })
  },
  inputJieciChange: function (e) {
    this.setData({
      jieci: e.detail.value
    })
  },
  inputChangduChange: function (e) {
    this.setData({
      changdu: e.detail.value
    })
  },
  //  点击提醒时间组件确定事件
  bindTimeChange: function (e) {
    this.setData({
      remindtime: e.detail.value
    })
  },
  flagChange: function (e) {
    let that = this;
    console.log(e)
    that.setData({
      flag: e.detail.value.length
    })
  },

  modifySchedule: function(){
    let that = this;
    //修改课程信息
    wx.request({
      url: app.globalData.url + '/updateSchedule',
      method: 'PUT',
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      data: {
        id: that.data.scheduleId,
        kctitle: that.data.kctitle,
        place: that.data.place,
        content: that.data.content,
        week: that.data.week,
        xingqi: that.data.xingqi,
        jieci: that.data.jieci,
        changdu: that.data.changdu,
        remindtime: that.data.remindtime,
        flag: that.data.flag
      },
      success: res => {
        wx.showToast({
          title: '修改成功',
          icon: 'success',
          duration: 3000
        });
      },
      fail: err => {
        wx.showToast({
          title: '失败',
          icon: 'error',
          duration: 3000
        });
      }
    });
  }
})